<?php
require_once 'InfoManager21.php';

$infoManager = new InfoManager();
$errorMessage = '';

// 验证ID参数
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    $_SESSION['error_message'] = '无效的记录ID';
    header('Location: show_info21.php');
    exit;
}

$id = intval($_GET['id']);

// 处理确认删除请求
if (isset($_POST['confirm'])) {
    if ($infoManager->deleteInfo($id)) {
        $_SESSION['success_message'] = '记录删除成功';
        header('Location: show_info21.php');
        exit;
    } else {
        $errorMessage = 'Error: 记录删除失败, 请稍后重试';
        // 记录详细错误日志
        error_log("Delete failed for ID $id: " . $infoManager->getLastError());
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>确认删除</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="confirm-container">
        <h2>确认删除</h2>

        <?php if ($errorMessage) : ?>
            <div class="error-message"><?php echo $errorMessage; ?></div>
        <?php endif; ?>

        <div class="warning">
            你确定要删除这条记录吗？此操作不可撤销！
        </div>

        <form action="" method="post">
            <div class="btn-group">
                <button type="submit" name="confirm" value="yes" class="btn btn-danger">确认删除</button>
                <a href="show_info21.php" class="btn btn-default">取消</a>
            </div>
        </form>
    </div>
</body>
</html>